﻿using System;
using System.Data;
using System.Collections.Generic;
using YiYiTong.Rocket.Helper;
using YiYiTong.Rocket.Entity;
using YiYiTong.Rocket.Model;
using YiYiTong.Rocket.DataAccess;
using YiYiTong.Rocket.EFDBFirst;
using System.Web;
using System.Linq;
using YiYiTong.Rocket.Business.Biz;

namespace YiYiTong.Rocket.Business
{
    public class JiesuanBiz
    {
        #region 单例模式
        private JiesuanBiz()
        {
        }

        private static JiesuanBiz _instance;
        private static readonly object _syncObject = new object();

        public static JiesuanBiz Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_syncObject)
                    {
                        if (_instance == null)
                        {
                            _instance = new JiesuanBiz();
                        }
                    }
                }
                return _instance;
            }
        }
        #endregion 单例模式

        public string GetSupplierDetailsName(ADZ_SupplierDetails aDZ_SupplierDetails)
        {

            string accountName = "--";
            switch (aDZ_SupplierDetails.channel)
            {
                case (int)SupplierPayChanner.Bank:
                    accountName = $"{aDZ_SupplierDetails.bank_account}【{aDZ_SupplierDetails.bank_name}】";
                    break;
                case (int)SupplierPayChanner.Alipay:
                    accountName = $"{aDZ_SupplierDetails.alipay_account}【{MyEnumHelper.GetEnumItemDescription<SupplierPayChanner>(aDZ_SupplierDetails.channel)}】";
                    break;
                case (int)SupplierPayChanner.Weixin:
                    accountName = $"{aDZ_SupplierDetails.wechat_account}【{MyEnumHelper.GetEnumItemDescription<SupplierPayChanner>(aDZ_SupplierDetails.channel)}】";
                    break;
            }
            return accountName;
        }

        public void WriteJiesuanLog(ADZ_JiesuanLog aDZ_JiesuanLog)
        {
            ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
            aDZ_JiesuanLog.create_time = DateTime.Now;
            aDZ_JiesuanLog.remark = aDZ_JiesuanLog.remark ?? "";
            dbcontext.ADZ_JiesuanLog.Add(aDZ_JiesuanLog);
            dbcontext.SaveChanges();
        }

    }
}
